<?php

namespace App\Filament\Admin\Resources\ComponentTypeResource\Pages;

use App\Filament\Admin\Resources\ComponentTypeResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;
use App\Models\Component as ComponentModel;

class EditComponentType extends EditRecord
{
    protected static string $resource = ComponentTypeResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Actions\DeleteAction::make(),
        ];
    }

    protected function afterSave(): void
    {
        $formData = $this->form->getState(); // Get the submitted form data
        $record = $this->record; // The saved Post model instance

        $demo_data = $record->demo_data;
        $component_tree = $record->component_tree;

        ComponentModel::findOrFail($record->component_id)->update([
             'demo_data' => $demo_data,
             'component_tree' => $component_tree,
        ]);
    }
}
